local skel = fk.CreateSkill {
  name = "emo__namichang",
}

skel:addEffect("active", {
  anim_type = "support",
  prompt = "#emo__namichang",
  card_num = 0,
  target_num = 1,
  target_filter = function (self, player, to_select, selected)
    return #selected < 2 and player ~= to_select
  end,
  times = function (self, player)
    return 1 - player:usedEffectTimes(skel.name, Player.HistoryPhase)
  end,
  can_use = function (self, player)
    return player:usedEffectTimes(skel.name, Player.HistoryPhase) < 1
  end,
  on_use = function (self, room, effect)
    local player = effect.from
    local tars = table.simpleClone(effect.tos)
    table.insert(tars, player)
    room:sortByAction(tars)
    for _, to in ipairs(tars) do
      if not to.dead then
        room:recover { num = 1, skillName = skel.name, who = to, recoverBy = player }
      end
    end
    if not player.dead then
      local ids = room:getCardsFromPileByRule(".|.|.|.|.|basic")
      if #ids > 0 then
        room:obtainCard(player, ids, true, fk.ReasonJustMove, player, skel.name)
      end
      room:changeShield(player, 1)
    end
    if not player.dead then
      local recover_num = 0
      player.room.logic:getEventsOfScope(GameEvent.Recover, 1, function(e)
        local rec = e.data
        if rec.who == player then
          recover_num = recover_num + rec.num
        end
        return recover_num > 1
      end, Player.HistoryTurn)
      if recover_num > 1 then
        local ids = room:getCardsFromPileByRule(".|.|.|.|.|trick")
        if #ids > 0 then
          room:obtainCard(player, ids, true, fk.ReasonJustMove, player, skel.name)
        end
      end
    end
  end,
})

skel:addEffect(fk.EnterDying, {
  anim_type = "support",
  can_trigger = function (self, event, target, player, data)
    return player:hasSkill(skel.name) and target == player and player:usedEffectTimes(self.name, Player.HistoryRound) == 0
  end,
  on_cost = function (self, event, target, player, data)
    local _ ,dat = player.room:askToUseActiveSkill(player, {
      skill_name = skel.name, skip = true,
    })
    if dat then
      event:setCostData(self, {tos = dat.targets})
      return true
    end
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    Fk.skills[skel.name]:onUse(room, {
      from = player, cards = {}, tos = event:getCostData(self).tos,
    })
  end,
})

Fk:loadTranslationTable{
  ["emo__namichang"] = "纳米场绽放",
  [":emo__namichang"] = "出牌阶段限一次，或你进入濒死状态（每轮限一次），你可以令你和一至两名其他角色各回复一点体力，并令你获得一张基本牌、一点护甲，若你本回合回复过两点体力，你获得一张锦囊牌。",
  ["#emo__namichang"] = "纳米场绽放：选择1-2名其他角色，你与其各回复1体力",
}


return skel
